package com.liuqi.knet.remoting;

import java.net.InetSocketAddress;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author liuqi
 * @date 2025/3/6 13:47
 **/
@Getter
@ToString
public class ClientConfig extends KNetConfig {

    /**
     * 远程连接地址
     */
    private InetSocketAddress remoteAddress;

    /**
     * 连接超时时间
     */
    private int connectTimeout = 30000;

    /**
     * 客户端连接失败重试次数
     */
    private int connectRetry = 0;

    public ClientConfig(InetSocketAddress remoteAddress) {
        this.remoteAddress = remoteAddress;
    }

    public void setRemoteAddress(InetSocketAddress remoteAddress) {
        this.remoteAddress = remoteAddress;
    }

    public void setConnectTimeout(int connectTimeout) {
        if (connectTimeout < 1000) {
            throw new IllegalArgumentException("connect timeout cannot less than 1000");
        }
        this.connectTimeout = connectTimeout;
    }

    public void setConnectRetry(int connectRetry) {
        if (connectRetry < 0) {
            throw new IllegalArgumentException("connect retry cannot less than 0");
        }
        this.connectRetry = connectRetry;
    }
}
